package com.epwk.action;


import com.epwk.driver.SeleniumDriver;
import com.epwk.element.WebEle;
import com.epwk.element.WebEles;
import com.epwk.logger.LoggerControler;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/13.
 */
public class Action extends SeleniumDriver {

    final static LoggerControler log= LoggerControler.getLogger(Action.class);

    public static void click(By by){
        WebEle.findElement(by).click();
        log.info("点击"+by);
    }

    public static void clear(By by){
        WebEle.findElement(by).clear();
        log.info("清空"+by);
    }

    public static void sendkeys(By by,String concent) {
        WebEle.findElement(by).sendKeys(concent);
        log.info("在"+by+"输入"+concent);
    }

    public static String getText(By by){
        String text = WebEle.findElement(by).getText();
        log.info(by+"的文本内容是"+text);
        return  text;
    }

    public static ArrayList getTexts(By by){
        ArrayList arrayList = new ArrayList();
        List<WebElement> webElements = WebEles.findElements(by);
        for (int i=0;i<webElements.size();i++){
            String text = webElements.get(i).getText();
            log.info(by+"的文本内容是"+text);
            arrayList.add(text);
        }
        return arrayList;
    }

    public static Boolean isDisplay(By by){
        Boolean isDisplay = WebEle.findElement(by).isDisplayed();
        log.info(by+"正常显示");
        return isDisplay;

    }

    public static Boolean isSelected(By by){
        Boolean isSelected = WebEle.findElement(by).isSelected();
        log.info(by+"可选取");
        return isSelected;
    }

    public static Boolean isEnable(By by){
        Boolean isEnable = WebEle.findElement(by).isEnabled();
        log.info(by+"处于激活状态");
        return isEnable;
    }

}
